#include <my/Time/Timer.h>

#include <algorithm>
#include <cassert>

namespace my {

    Timer::Timer() : _clock(), _timeLimit(0.f)
    {

    }

    Timer::Timer(float timeLimit, bool initRunning) : _clock(initRunning), _timeLimit(timeLimit)
    {
        assert(timeLimit > 0.f);
    }

    Timer::~Timer()
    {

    }





    float   Timer::getRemainingTime()      const
    {
        return std::max((_timeLimit - _clock.getElapsedTime()), 0.f);
    }

    bool    Timer::isRunning()             const
    {
        return (_clock.isRunning() && !isExpired());
    }

    bool    Timer::isExpired()             const
    {
        return (_clock.getElapsedTime() > _timeLimit);
    }

    void    Timer::start()
    {
        _clock.start();
    }

    void    Timer::stop()
    {
        _clock.stop();
    }

    void    Timer::reset(float timeLimit, bool continueRunning)
    {
        assert(timeLimit > 0.f);

        _timeLimit = timeLimit;
        _clock.reset(continueRunning);
    }

    void    Timer::reset(bool continueRunning)
    {
        _clock.reset(continueRunning);
    }




}
